<?php
require_once 'db.php';


class san_pham extends DB{
    
    public $table_name='san_pham';
    public function __construct() {
        parent::getConnection();
    }
    public  function select($params=array(),$page=1,$couter=false){
        $limit='';
        if (!empty($page)) {
            $start = ($page - 1) * HOME_PER_PAGE;
            $limit = "LIMIT $start,".HOME_PER_PAGE;
        }
        
        $where=' where ( 1=1 )';
        if(isset($params['id']))
            $where.=' AND (id='.$params['id'].') ';
        
        if(isset($params['chuan_loai']))
            $where.=' AND (chuan_loai='.$params['chuan_loai'].') ';
              
        if (!empty($page)&& !empty($params['hot'])) {
            $page=2;
            $start = ($page - 1) * HOME_PER_PAGE;
            $limit = "LIMIT $start,".HOME_PER_PAGE;
        }
        
        if(isset($params['nam'])){
           $where.=' AND (gioi_tinh='.$params['nam'].') ';
           $start = ($page - 1) * NAM_NU_PER_PAGE;
            $limit = "LIMIT $start,".NAM_NU_PER_PAGE;
        }
        if(isset($params['nu'])){
           $where.=' AND (gioi_tinh='.$params['nu'].') ';
           $start = ($page - 1) * NAM_NU_PER_PAGE;
            $limit = "LIMIT $start,".NAM_NU_PER_PAGE;
        }
        
        
        
        $query='SELECT * FROM '.$this->table_name.$where.$limit;
        //var_dump($query);
        $result= mysql_query($query);
        $rows=array();
        while ($row = mysql_fetch_assoc($result)) {
            $rows[]=$row;   
        }
        return $rows;
    }
    
            function update($params=null){
        $query="UPDATE $this->table_name SET name=".$params['name']."WHERE id=".$params['id'];
            mysql_query($query);
                return mysql_query($query);
        ;
    }
}
